import { defineStore } from "pinia";

export const useUserStore = defineStore("main", {
  state: () => {
    return {
      name: "zs",
      age: 25,
      sex: "男",
    };
  },
  //可理解为计算属性
  getters: {
    getAddAge: (state) => {
      return state.age + 100;
    },
    getAddAges: (state) => {
      return (num: number) => state.age + num;
    },
    getNameAndAge(): string {
      return this.name + this.getAddAge; //调用其他getter
    },
  },
  //同步异步都在这里写
  actions: {
    saveName(name: string) {
      this.name = name;
    },
  },
});
